package com.atguigu.yygh.hosp.controller;/*
 * @author: XueYouPeng
 * @time: 2023/6/9 21:03
 */

import com.atguigu.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
//@CrossOrigin
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    HospitalService hospitalService;
    private Map<String, Object> map;

    /*
     * 医院分页
     * @author: XueYouPeng
     * @time: 2023/6/9 21:04
     */
     @PostMapping("{pageNum}/{pageSize}")
     public Result hospitalList(
             @PathVariable Integer pageNum,
             @PathVariable Integer pageSize,
             @RequestBody HospitalQueryVo hospitalQueryVo
     ){
         Page<Hospital> page = hospitalService.hospitalList(pageNum,pageSize,hospitalQueryVo);

         //所需要的参数
         List<Hospital> list = page.getContent();
         long total = page.getTotalElements();

         return Result.ok().data("list",list).data("total",total);
     }

     /*
      * 根据id修改医院的status，实现上线和下线
      * @author: XueYouPeng
      * @time: 2023/6/11 11:49
      */
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    /*
     * 查询医院详情
     * @author: XueYouPeng
     * @time: 2023/6/11 12:14
     */
    @GetMapping("/getHospById/{id}")
    public Result getHospById(@PathVariable String id){
        //hospital bookingRule 两个参数
        Map<String,Object> map = hospitalService.getHospById(id);
        return Result.ok().data("item",map);
    }
}
